package com.hello.webmagic;

import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.pipeline.ConsolePipeline;
import us.codecraft.webmagic.processor.PageProcessor;

import java.util.List;

/**
 * @author : zga
 * @date : 2016-11-09
 */
public class WebmagicDemo implements PageProcessor {
    private Site site = Site.me().setDomain("http://www.iliyu.com/");

    @Override
    public void process(Page page) {
        List<String> links = page.getHtml().links().regex("http://www.iliyu.com/download.aspx?sid=30062").all();
        page.addTargetRequests(links);
        page.putField("name", page.getHtml().xpath("//div[@class='eMuleMain']/table/tr/td/a/@vyxdheeb").toString());
    }

    @Override
    public Site getSite() {
        return site;

    }

    public static void main(String[] args) {
        Spider.create(new WebmagicDemo())
                .addUrl("http://www.iliyu.com/download.aspx?sid=30062")
                .addPipeline(new ConsolePipeline()).run();
    }

}

